using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using MiniAnimation;
using UnityEngine;

public class SeqItem:MonoBehaviour
{
    [SerializeField] RectTransform rect;
    Vector2 originPos;
    MiniAnimate.MiniSequence seq;
    private void Awake() {
        originPos = rect.anchoredPosition;
    }
    public async Task DoAnimAsync()
    {
        //归位
        rect.anchoredPosition = originPos;
        rect.localRotation = Quaternion.identity;

        //杀死动画序列
        if (seq != null)
        {
            seq.Kill();
        }
        //初始化
        seq = MiniAnimate.Sequence();
        //添加动画
        seq.Append(rect.MiniAncMoveX(originPos.x - rect.rect.width * 1f, 0.6f, MiniCurve.OutBack));
        //与上一个并行
        seq.Join(rect.MiniRotate(new Vector3(0, 0, 190), 0.6f, MiniCurve.OutBack));
        seq.Append(rect.MiniAncMoveX(originPos.x, 0.6f, MiniCurve.OutBack));
        seq.Join(rect.MiniRotate(new Vector3(0, 0, 0), 0.6f, MiniCurve.OutBack));
        // seq.Append(rect.MiniAncMoveX(originPos.x - rect.rect.width * 1f, 0.6f, MiniCurve.OutBack));
        // seq.Join(rect.MiniRotate(new Vector3(0, 0, 0), 0.6f, MiniCurve.OutBack));
        //添加Action执行
        seq.AppendAction(() =>
        {
            Debug.Log("action 执行");
        });
        seq.AppendUnitaskFunc(Test);
        seq.AppendTaskFunc(Test1);
        //完成的回调
        seq.OnCompleted += () =>
        {
            Debug.Log("CallBack 执行");
        };
        //执行
        seq.Excute();
        //等待执行完毕
        await seq.Task;
        Debug.Log("Await Over");
    }
    async UniTask Test()
    {
        // await UniTask.Delay(1000);
        Debug.Log("Test1");
    }
    async Task Test1()
    {
        // await UniTask.Delay(1000);
        Debug.Log("Test2");
    }
}